package com.mayflygeek.mayflyask.framework.orm.entity;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.MoreObjects;

/**
 * @author 虫虫
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 * @Emial chongchong@mayflygeek.com
 * 
 */
@MappedSuperclass
public abstract class NameEntity extends IdEntity {
	private static final long serialVersionUID = -2640031884003372096L;
	
	/**
	 * 名称
	 */
	@Column(nullable = false, length = 100)
	@NotEmpty
	@Size(min = 2, max = 100)
	private String name;
	
	/**
	 * 描述
	 */
	@Column(length = 500)
	@Size(max = 500)
	private String description;
	
	public NameEntity() {
		
	}
	
	public NameEntity(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Override
	public String toString() {
		return MoreObjects.toStringHelper(this).add("id",getId()).add("name",name).add("description", description).toString();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((name == null) ? 0 :name.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj) {
			return true;
		}
		if(!super.equals(obj)) {
			return false;
		}
		if(getClass() != obj.getClass()) {
			return false;
		}
		NameEntity other = (NameEntity) obj;
		if (description == null) {
			if(other.description != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}
}
